<?php

//cron item

class CronJob extends CronAppModel {

	var $name = 'CronJob';

	function shouldRun($frequency) {
		$freq = split(' ', $frequency);
		$dMonth = false;
		$dMonth = ($freq[0] == '*') ? true : in_array(date('j'), $this->parseValue($freq[0]));
		$month = ($freq[1] == '*') ? true : in_array(date('n'), $this->parseValue($freq[1]));
		$day = ($freq[2] == '*') ? true : in_array(date('w'), $this->parseValue($freq[2]));
		$either = (($freq[0] != '*') && ($freq[2] != '*'));
		//echo date('j n w'), 'dm', $dMonth,'m', $month,'d', $day;
		return (($month && $dMonth && $day) || ($either && $month && ($dMonth || $day)));
	}
	
	function parseValue($str) {
		$ret = array();
		if (strpos($str, '-')) {
			list($start, $end) = split('-', $str);
			for ($i = $start; $i <= $end; $i++) {
				$ret[] = $i;
			}
		} else {
			$ret = split(',', $str);
		}
		//pr($ret);
		return $ret;
	}

}

?>